<?php

namespace App\Admin\Controllers;

use App\AdminPermission;
use Illuminate\Http\Request;

class PermissionController extends Controller
{
    //
    public function index()
    {
        $permissions = AdminPermission::orderBy('created_at', 'desc')->paginate(20);
        return view('admin.permission.index', compact('permissions'));
    }

    public function create()
    {
        return view('admin.permission.add');
    }

    public function store()
    {
        //验证
        $this->validate(\request(), [
            'name' => 'required | string',
            'description' => 'required | String'
        ]);

        $params = \request(['name', 'description']);
         $permission = AdminPermission::create($params);

        //渲染
        return redirect('admin/permissions');
    }
}
